package org.javaboy.curator;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.data.Stat;

public class CuratorDeleteDemo {
    public static void main(String[] args) throws Exception {
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
        CuratorFramework client = CuratorFrameworkFactory.newClient("s2.javaboy.org:2181", 5000, 10000, retryPolicy);
        //建立连接
        client.start();
        //查询数据
        Stat stat = new Stat();
        byte[] bytes = client.getData().storingStatIn(stat).forPath("/javaboy");
        System.out.println("stat = " + stat);
        System.out.println(new String(bytes));
        //正常删除，/javaboy 下不能有子节点
//        client.delete().forPath("/javaboy");
        client.delete().deletingChildrenIfNeeded().forPath("/javaboy");
    }
}
